package cliente;

import java.awt.Canvas;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;

public class Reproductor extends Thread{
	
	private JFrame panel;
	private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
	private String ruta;
	private boolean play;
	
	public Reproductor(String ruta){
		play=false;
		new NativeDiscovery().discover();		
		
		this.ruta=ruta;
		
		mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
		panel=new JFrame("Video");
		panel.setLocation(0, 0);
		panel.setSize(1366, 768);
		panel.setContentPane(mediaPlayerComponent);
		panel.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	public void run(){		
		try {
			panel.setVisible(true);
			panel.setBackground(Color.BLUE);
			Thread.sleep(10000);
			play=true;
			mediaPlayerComponent.getMediaPlayer().playMedia(ruta);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public boolean playAndPause(){
		if(play){
			mediaPlayerComponent.getMediaPlayer().pause();
			return play=false;
		}else{
			mediaPlayerComponent.getMediaPlayer().pause();
			return play=true;
		}
	}

	public void cerrar() {
		mediaPlayerComponent.getMediaPlayer().stop();
		if(this.isAlive()){
			this.interrupt();
		}
		panel.dispose();
	}
}

